package UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Scanner;

public class ClientDemo1 {

    public static void main(String[] args) throws Exception {
        //创建发送端对象，发送端自带默认端口号
        DatagramSocket socket = new DatagramSocket();
//        byte[] buffer="shuzijun".getBytes();


        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("请说:");
            String msg = scanner.nextLine();

            if ("exit".equals(msg)){
                System.out.println("离线成功！");
                socket.close();
                break;
            }

            byte[] buffer=msg.getBytes();
            DatagramPacket packet=new DatagramPacket(buffer,buffer.length, InetAddress.getLocalHost(),9999);
            socket.send(packet);
        }

    }
}
